<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Examinees Admin</title>
</head>
<body>
	<c:set var="user" value="${sessionScope.user}"></c:set>
	<c:if test="${user.userType ne 'Professor'}" >
		<c:redirect url="LoginServlet"></c:redirect>
	</c:if>
	<c:set var="message" value="${param.message}"></c:set>
	<c:set var="error" value="${param.error}"></c:set>
	<c:set var="success" value="${param.success}"></c:set>

	<div id="header"><%@ include file="Header.jsp"%></div>
	<div id="content">
	<div id="navbar"><%@ include file="NavigationBar.jsp"%></div>
	
	<div id="main">
	
		<div style="" class="box">
			<div class="box-header well">
				<h2><i class="icon-user"></i> Add Examinee</h2>
				<div class="box-icon">
					<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
				</div>
			</div>
			
			<div class="box-content">
				<form class="form-horizontal" action="AddStudentServlet" method="post">
					<fieldset>
						<label class="control-label">Examinee Information:</label>
						<br><br>
						<div class="control-group">
							<label class="control-label" for="focusedInput">*First Name</label>
							<div class="controls">
								<input name="first_name" class="input-xlarge focused" type="text">
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="focusedInput">*Last Name</label>
							<div class="controls">
								<input name="last_name" class="input-xlarge focused" type="text">
							</div>
						</div>
						<br>
						<label class="control-label">Examinee Credentials:</label>
						<br><br>
						<div class="control-group">
							<label class="control-label" for="focusedInput">*Password</label>
							<div class="controls">
								<input name="password" class="input-xlarge focused" type="password">
							</div>
						</div>
					</fieldset>	
						
					<fieldset>
						<div class="form-actions">
							<button type="submit" class="btn btn-primary" name="addExaminee">Add Examinee</button>
							<button class="btn" type="reset">Reset</button>
						</div>
					</fieldset>	  
				</form>   
			</div>
		</div>
		
				
		<div class="box">
			<div class="box-header well">
				<h2><i class="icon-th-list"></i> View Examinees</h2>
				<div class="box-icon">
					<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
				</div>
			</div>
			<div class="box-content">
				<table class="table table-striped table-bordered bootstrap-datatable datatable">
					<thead>
						<tr>
							<th>Examinee ID</th>
							<th>Last Name</th>
							<th>First Name</th>
							<th>Password</th>
							<th>Status</th>
							<th>Action</th>
						</tr>
					</thead>   
					<tbody>
						<c:forEach var="students" items="${user.getStudents()}">
							<tr>
							<td>${students.userId}</td>
							<td>${students.lastName}</td>
							<td>${students.firstName}</td>
							<td>${students.password}</td>
							<td>
								<c:choose>
									<c:when test="${students.activated eq true}">
										<label class="label label-success" style="text-align: center">Active</label>
									</c:when>
									<c:otherwise>
										<label class="label label-important" style="text-align: center">Inactive</label>
									</c:otherwise>
								</c:choose>
							</td>
							<td>
								<c:choose>
									<c:when test="${students.activated eq true}">
										<a class="btn btn-danger" href="ActivateStudentServlet?student_id=${students.userId}"><i class="icon-remove"></i> Deactivate</a>
									</c:when>
									<c:otherwise>
										<a class="btn btn-success" href="ActivateStudentServlet?student_id=${students.userId}"><i class="icon-plus"></i> Activate</a>
									</c:otherwise>
								</c:choose>
							</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
		</div>

	<c:choose>
	<c:when test="${not empty message}">
	<script>$(document).ready(function() {$.noty({ text: '${message}', type: 'information', layout: 'top'});});</script>
	</c:when>
	<c:when test="${not empty error}">
	<script>$(document).ready(function() {$.noty({ text: '${error}',type: 'error',layout: 'top'});});</script>
	</c:when>
	<c:when test="${not empty success}">
	<script>$(document).ready(function() {$.noty({text: '${success}',type: 'success',layout: 'top'});});</script>
	</c:when>
	</c:choose>
	
	</div>
	</div>
	
	<script>
		$(document).ready(function() {
			$("button[name='addExaminee']").click(function() {
				var success = true;

				$(".help-inline").remove();
				
				if($("input[name='first_name']").val().length == 0) {
					$("input[name='first_name']").after("<span class='help-inline'>Empty Field!</span>").parent().parent().addClass("error");
					success = false;
				} 
				else{
					$("input[name='first_name']").parent().parent().removeClass("error");
				}
				
				if($("input[name='last_name']").val().length == 0) {
					$("input[name='last_name']").after("<span class='help-inline'>Empty Field!</span>").parent().parent().addClass("error");
					success = false;
				} 
				else{
					$("input[name='last_name']").parent().parent().removeClass("error");
				}
				
				if($("input[name='password']").val().length == 0) {
					$("input[name='password']").after("<span class='help-inline'>Empty Field!</span>").parent().parent().addClass("error");
					success = false;
				}
				else if($("input[name='password']").val().length < 7) {
					$("input[name='password']").after("<span class='help-inline'>Must Be Atleast 7 Characters!</span>").parent().parent().addClass("error");
					success = false;
				}
				else{
					$("input[name='password']").parent().parent().removeClass("error");
				}
				
				return success;
			});
		});
	</script>

</body>
</html>